package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.eneity.SpuInfo;
import com.atguigu.gmall.product.service.SpuInfoService;
import com.atguigu.gmall.product.vo.SaveSpuInfoVo;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "spu列表")
@RestController
@RequestMapping("admin/product")
public class SpuInfoController {

    @Autowired
    SpuInfoService spuInfoService;

    //{page}/{limit}?category3Id=61
    @ApiOperation("获取spu分页列表")
    @GetMapping("/{ps}/{pn}")
    public Result getSpuInfo(@PathVariable("ps") Long ps ,
                             @PathVariable("pn") Long pn ,
                             @RequestParam("category3Id") Long category3Id){

        Page<SpuInfo> page = spuInfoService.lambdaQuery().eq(SpuInfo::getCategory3Id, category3Id)
                .page(new Page<>(ps, pn));
        return Result.ok(page);
    }

    @ApiOperation("添加SpuInfo属性")
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SaveSpuInfoVo saveSpuInfoVo){

        spuInfoService.saveSpuInfo(saveSpuInfoVo);
        return Result.ok();
    }
}
